import Vue from 'vue';
import App from './App.vue';
import router from './router/index.js';
import '@/assets/style/reset.css';
import { defaultCover, tolerant, judgeScrollBar, clickOutside } from '@/directives/index.ts';
import { Loading, Message } from 'element-ui';
import global from './config/index.ts';
import localforage from 'localforage';
import { getUserId } from '_t';

const localforageNamePrefix = global.localforageNamePrefix;
getUserId().then(userid => {
  Vue.prototype.$localforageIns = localforage.createInstance({
    name: localforageNamePrefix + userid
  });
});

Vue.prototype.$messageInfo = (message: string) => {
  Message.info({
    message,
    iconClass: 'message-info'
  });
};

Vue.directive('defaultCover', defaultCover);
Vue.directive('tolerant', tolerant);
Vue.directive('judgeScrollBar', judgeScrollBar);
Vue.directive('clickOutside', clickOutside);
Vue.use(Loading);

const matrixComp = [
  'thsc-mbweb-charge_pcRadios@1.0.1',
  'thsc-mbweb-charge_pcHeader@1.0.3',
  'thsc-mbweb-charge_pcAime@1.0.3-beta.5'
];
matrixComp.forEach(comp => {
  Vue.use((window as any)[comp].default);
});

new Vue({
  render: h => h(App),
  router
}).$mount('#app');
